From: Ewan Mellor Date: Mon, 25 Dec 2006 19:29:05 +0000 (+0000) Subject: Implement VM_BAD_POWER_STATE handling. X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~15422^2~153 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/%22bookmarks://%22Dat/%22http:/www.example.com/cgi/%22https:/%22bookmarks:/%22Dat?a=commitdiff_plain;h=894243ac7bd572612b6264b2287f7d79ccee7168;p=xen.git Implement VM_BAD_POWER_STATE handling. Signed-off-by: Ewan Mellor --- diff --git a/tools/python/xen/xend/XendAPI.py b/tools/python/xen/xend/XendAPI.py index 1ca52aa5d4..acd8a0e409 100644 --- a/tools/python/xen/xend/XendAPI.py +++ b/tools/python/xen/xend/XendAPI.py @@ -260,10 +260,14 @@ def do_vm_func(fn_name, vm_ref, *args, **kwargs): @param *args: more arguments @type *args: tuple """ - xendom = XendDomain.instance() - fn = getattr(xendom, fn_name) - xendom.do_legacy_api_with_uuid(fn, vm_ref, *args, **kwargs) - return xen_api_success_void() + try: + xendom = XendDomain.instance() + fn = getattr(xendom, fn_name) + xendom.do_legacy_api_with_uuid(fn, vm_ref, *args, **kwargs) + return xen_api_success_void() + except VMBadState, exn: + return xen_api_error(['VM_BAD_POWER_STATE', vm_ref, exn.expected, + exn.actual]) class XendAPI: diff --git a/tools/python/xen/xend/XendDomain.py b/tools/python/xen/xend/XendDomain.py index ce6d487766..d0cb8cfabb 100644 --- a/tools/python/xen/xend/XendDomain.py +++ b/tools/python/xen/xend/XendDomain.py @@ -36,6 +36,7 @@ from xen.xend import XendRoot, XendCheckpoint, XendDomainInfo from xen.xend.PrettyPrint import prettyprint from xen.xend.XendConfig import XendConfig from xen.xend.XendError import XendError, XendInvalidDomain, VmError +from xen.xend.XendError import VMBadState from xen.xend.XendLogging import log from xen.xend.XendAPIConstants import XEN_API_VM_POWER_STATE from xen.xend.XendConstants import XS_VMROOT @@ -782,7 +783,9 @@ class XendDomain: raise XendError("Cannot save privileged domain %s" % domname) if dominfo.state != DOM_STATE_RUNNING: - raise XendError("Cannot suspend domain that is not running.") + raise VMBadState("Domain is not running", + POWER_STATE_NAMES[DOM_STATE_RUNNING], + POWER_STATE_NAMES[dominfo.state]) dom_uuid = dominfo.get_uuid() @@ -932,7 +935,9 @@ class XendDomain: raise XendInvalidDomain(str(domid)) if dominfo.state != DOM_STATE_HALTED: - raise XendError("Domain is already running") + raise VMBadState("Domain is already running", + POWER_STATE_NAMES[DOM_STATE_HALTED], + POWER_STATE_NAMES[dominfo.state]) dominfo.start(is_managed = True) self._add_domain(dominfo) @@ -960,7 +965,9 @@ class XendDomain: raise XendInvalidDomain(str(domid)) if dominfo.state != DOM_STATE_HALTED: - raise XendError("Domain is still running") + raise VMBadState("Domain is still running", + POWER_STATE_NAMES[DOM_STATE_HALTED], + POWER_STATE_NAMES[dominfo.state]) log.info("Domain %s (%s) deleted." % (dominfo.getName(), dominfo.info.get('uuid'))) diff --git a/tools/python/xen/xend/XendError.py b/tools/python/xen/xend/XendError.py index 5947145267..5033560ea3 100644 --- a/tools/python/xen/xend/XendError.py +++ b/tools/python/xen/xend/XendError.py @@ -32,6 +32,16 @@ class XendError(Fault): def __str__(self): return self.value +class VMBadState(XendError): + + def __init__(self, value, expected, actual): + XendError.__init__(self, value) + self.expected = expected + self.actual = actual + + def __str__(self): + return self.value + class VmError(XendError): """Vm construction error.""" pass diff --git a/tools/python/xen/xm/messages/en/xen-xm.po b/tools/python/xen/xm/messages/en/xen-xm.po index 75d7f5e6fc..28cb03efec 100644 --- a/tools/python/xen/xm/messages/en/xen-xm.po +++ b/tools/python/xen/xm/messages/en/xen-xm.po @@ -19,7 +19,7 @@ msgid "" msgstr "" "Project-Id-Version: Xen-xm 3.0\n" -"PO-Revision-Date: 2006-12-23 11:04+0000\n" +"PO-Revision-Date: 2006-12-25 19:24+0000\n" "Last-Translator: Ewan Mellor \n" "Language-Team: xen-devel \n" "MIME-Version: 1.0\n" @@ -65,3 +65,5 @@ msgstr "The VM handle %(1)s is invalid." msgid "VTPM_HANDLE_INVALID" msgstr "The VTPM handle %(1)s is invalid." +msgid "VM_BAD_POWER_STATE" +msgstr "The VM must be %(2)s to perform the requested operation (it is currently %(3)s)."